using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using ProjectConfigurator;

namespace XmlObjects
{
	
	public partial class PropertyPage : Form
	{
		private ObjectReader objectReader;
		private object theObject;
		public PropertyPage(object theObject)
		{
			this.theObject = theObject;
			InitializeComponent();
			Point currentLocation = new Point(0, 0);
			objectReader = new ObjectReader(theObject);
			foreach (KeyValuePair<string, IPropertyItem> keyValuePair in objectReader.Properties)
			{
				Control aControl = keyValuePair.Value.GetControl();
				aControl.Location = currentLocation;
				panel1.Controls.Add(aControl);

				currentLocation = new Point(0, currentLocation.Y + aControl.Size.Height + 1);

			}
		}

		private void PropertyPage_Load(object sender, EventArgs e)
		{

		}

		private void button_ok_Click(object sender, EventArgs e)
		{
			foreach (KeyValuePair<string, IPropertyItem> pair in objectReader.Properties)
			{
				pair.Value.PropertyInfo.SetValue(this.theObject, pair.Value.GetValue(), null);
			}
			this.Close();
			
		}

		private void button_cancel_Click(object sender, EventArgs e)
		{
			this.Close();
		}
	}
}
